<!DOCTYPE html>
<html lang="en">
<head>
    {{include file="lib/page_head" /}}

    <style>
        table th{word-wrap:break-word;word-break:break-all;font-size:12px!important;}
        table td{word-wrap:break-word;word-break:break-all;font-size:12px!important;}
        .from_table .td_l,.from_table .td_r{font-size:14px!important;line-height: 25px;word-wrap:break-word;word-break:break-all}
        #search_form .form-control,#search_form .select5{width:100px;height:28px;padding:5px;}
        #search_form .layui-input-inline{width:auto;margin: 0;}
        #search_form .form-group{margin-right:0;margin-bottom: 5px;}
        #search_form .btn{height:30px;line-height:30px;padding:0 10px;}
    </style>
</head>

<body>



<!-- Preloader -->
<div id="preloader">
    <div id="status"><i class="fa fa-spinner fa-spin"></i></div>
</div>

<section>
    {{include file="lib/page_left" /}}
    <div class="mainpanel">

        {{include file="lib/page_header" /}}

        <div class="contentpanel" >
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="panel-btns">
                        <a href="" class="panel-close">×</a>
                        <a href="" class="minimize">−</a>
                    </div>
                    <h4 class="panel-title">充值套餐列表</h4>
                </div>
                <div class="panel-body ">
                    <div id="info_list" class="form-inline">
                        <div class="btn-group">
                            <button class="btn btn-primary" onclick="edit_info(0)">添加</button>
                            <button class="btn btn-primary" onclick="scanQRCode(0)">微信扫一扫</button>
                            <!--<button class="btn btn-primary" onclick="set_cancel(0)">取消</button>-->
                            <button class="btn btn-primary" onclick="location.href = location.href;">刷新</button>

                        </div>
                        <div class="layui-form-item search_tools" style="margin-top:10px;" >
                            <form class="layui-form" id="search_form" action="" onsubmit="return false;">
                                <div class="form-group">
                                    <label >充值卡密码</label>
                                    <input class="form-control" name="card_pwd"  autocomplete="off" type="text">
                                </div>



                                <div style="display: inline-block;clear: both;">
                                    <button class="btn btn-primary" onclick="search()">查询</button>
                                    <button class="btn btn-default" onclick="search_reset()">取消</button>
                                </div>
                            </form>
                            <div class="well well-sm search_toogle"><span class="glyphicon glyphicon-chevron-down"></span></div>
                        </div>
                    </div>
                </div>
            </div>
        </div><!-- contentpanel -->

    </div><!-- mainpanel -->
    {{include file="lib/page_right" /}}
</section>
<div id="edit_info" style="display: none;">
    <div class="layui-form-item" style="margin:10px;">
        <form>
            <div  class="form-group">
                <label > 充值卡密码	<span style="color:red;">*</span></label>
                <input class="form-control" placeholder="充值卡密码" name="card_pwd" type="text">
            </div>
            <div  class="form-group">
                <label > 金额<span style="color:red;">*</span></label>
                <input class="form-control" placeholder="金额" name="money" type="number">
            </div>

        </form>
    </div>
</div>
<script src="../js/jquery-1.11.1.min.js"></script>
<script src="../js/jquery-migrate-1.2.1.min.js"></script>
<script src="../js/jquery-ui-1.10.3.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/jquery.sparkline.min.js"></script>
<script src="../js/toggles.min.js"></script>
<script src="../js/jquery.cookies.js"></script>
<script src="../js/jquery.tmpl.js"></script>
<script src="../js/custom.js"></script>
<script src="../layui/layui.js"></script>
<script src="../js/jquery.gritter.min.js"></script>
<script src="../js/form.beautify.js?t={{$version}}"></script>
<script src="../js/commen.js?t={{$version}}"></script>
<script src="../js/datatables.js?t={{$version}}"></script>
<link href="../css/ley.dialog.css" rel="stylesheet">
<script src="../js/ley.dialog.js?t={{$version}}"></script>
<script src="../js/jweixin-1.3.2.js"></script>
<script>
    layui.use(['laydate','laypage',"element"], function(){

    });
    var admin_id = "{{$ADMIN_ID}}";
    var is_weixin = (function(){return navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1})();

    $(function () {
        wx.config({
            debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
            appId: '{{$w_config.appId}}', // 必填，企业号的唯一标识，此处填写企业号corpid
            timestamp: "{{$w_config.timestamp}}", // 必填，生成签名的时间戳
            nonceStr: '{{$w_config.nonceStr}}', // 必填，生成签名的随机串
            signature: '{{$w_config.signature}}',// 必填，签名，见附录1
            jsApiList: ['hideMenuItems','onMenuShareTimeline','onMenuShareAppMessage','scanQRCode'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
        });
        wx.ready(function(){


            // confaig信息验证后会执行ready方法，所有接口调用都必须在config接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在ready函数中。
        });

        $("#info_list").datatables({
            idField: 'order_no',
            mobile_field:["ck","card_pwd_text","status"],
            columns:[
                {field:'ck',checkbox:true },
                {field:'id',title:'编号',width:30},
                {field:'card_pwd_text',title:'充值卡密码',width:100},
                {field:'money',title:'金额',width:50, formatter: function (value, row, index) {return (value * 0.0001).toFixed(2) + "";}},
                {field:'ctime',title:'时间',width:50, formatter: function (value, row, index) {return getLocalTime(value) + "";}},
                {field:'status',title:'状态',width:30,formatter:function (value,row,index) {
                        if(value===1){
                            return "使用中";
                        }else if(value===2){
                            return "已充值";
                        }else if(value===3){
                            return "异常";
                        }else{
                            return "未使用";
                        }
                    }}


            ],
            ajax:{
                url:"/card/ajax_recharge_card_list",
                parems:get_search_data(),
                callback:function (msg) {
                    check_table_list_data(msg);
                    check_parent_height();
                }
            }

        });
    });
    function setScan(card_pwd)
    {

        $("#edit_info form")[0].reset();
        openDialog2({title:"加油卡信息",area: ['500', "600"],content:$("#edit_info"),clone:true,before:function (layero) {
                $("input[name='card_pwd']",layero).val(card_pwd);
            },
            yes:function (index,layero) {
                var card_pwd = $("input[name='card_pwd']",layero).val();
                var money = $("input[name='money']",layero).val();
                AjaxCommen("GET","/card/ajax_recharge_card_save",{'card_pwd':card_pwd,'money':money},function (msg) {
                    if(msg.error === 0)
                    {
                        openMsg("成功");
                        layero.close();
                        search();

                    }
                });
            }
        });
    }
    function scanQRCode()
    {
        if(!is_weixin)
        {
            openMsg("请在微信中打开");
            return ;
        }
        wx.ready(function() {
            wx.scanQRCode({
                needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
                scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码，默认二者都有
                success: function (res) {
                    var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
                    if(result.substring(0,8) === "CODE_128")
                    {
                        var card_pwd = result.substring(9);
                        setScan(card_pwd);

                    }

                },
                error: function (res) {
                    if (res.errMsg.indexOf('function_not_exist') > 0) {
                        alert('版本过低请升级')
                    }
                    alert(res)
                }
            });
        });
    }
    function edit_info(id) {
        $("#edit_info form")[0].reset();
        $("#edit_info").find("input[name='id']").val(0);

        open_info();
    }
    function open_info()
    {
        $("#edit_info select").trigger("change");
        openDialog2({title:"加油卡信息",area: ['500', "600"],content:$("#edit_info"),clone:true,before:function (layero) {

            },
            yes:function (index,layero) {
                var data = {};
                var is_false = false;

                $("#edit_info input[type!='radio'],#edit_info select,#edit_info textarea,#edit_info input[type='radio']:checked",layero).each(function () {
                    var name = $(this).attr("name");

                    if(name)
                    {
                        var value = $(this).val();

                        if(value)
                        {
                            data[name] = value;
                            $(this).parents(".form-group").removeClass("has-error");
                        }else{
                            $(this).parents(".form-group").addClass("has-error");
                            is_false = true;

                        }
                    }
                });
                if(is_false)
                {
                    return false;
                }
                AjaxCommen("GET","/card/ajax_recharge_card_save",data,function (msg) {
                    if(msg.error === 0)
                    {
                        openMsg("成功");
                        layero.close();
                        search();
                    }
                });
            }
        });
    }

    function search()
    {
        var data = get_search_data();
        $("#info_list").setParems(data);
        $("#info_list").reload();

    }
    function search_reset() {
        $("#search_form")[0].reset();
        search();
    }
    function get_search_data() {
        var data = {};
        $('#search_form select,#search_form input').each(function () {
            var name = $(this).attr("name");
            if(name)
            {
                data[name] = $(this).val();
            }

        });
        return data;
    }
</script>

</body>
</html>
